import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver(),
      IconsResolver(),],

    }),
    Components({
      resolvers: [ElementPlusResolver({ importStyle: "sass" }),
      IconsResolver({
        enabledCollections: ['ep'],
      }),
      ],
    }),
    Icons({
      autoInstall: true,
    }),
  ],
  resolve: {
    //实际路径转换
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        // 自动导入定制化样式文件进行样式覆盖
        additionalData: `
          @use "@/styles/element/index.scss" as *;
        `,
      }
    }
  },
  lintOnSave: false,
  server: {
    open: true,
    port: 5173,
    proxy: {
      '/api': {//获取路径中包含了/api的请求
        target: 'http://localhost:8080',//后台服务所在的源
        changeOrigin: true,//修改源
        rewrite: (path) => path.replace(/^\/api/, '')// /api替换为空字符串
      },
    }
  }
})
